// fenxiao/businSum/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentPage: 1,
    loadMoreHidden: 1,
    currentType: 1,//1日报2周报3月报
    selectDate: '',
    childWxStoreList: [],
    search: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getChildWxStoreList();
  },
  getChildWxStoreList: function () {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/WxStore/GetChildWxStoreList?uid=' + app.globalData.userInfo.Uid + '&nickName=' + that.data.search + '&page=' + that.data.currentPage,
      success: function (res) {
        if (res.data.Code == 0) {
          let childWxStoreList = res.data.Data.Items;
          if(that.data.currentPage != 1){
            let preList = that.data.childWxStoreList;
            childWxStoreList = preList.concat(childWxStoreList);
          }
          for (let i = 0; i < childWxStoreList.length; i++) {
            childWxStoreList[i].date = childWxStoreList[i].createtime.substr(0, 10);
            childWxStoreList[i].time = childWxStoreList[i].createtime.substr(11, 8);
            if (parseFloat(childWxStoreList[i].FirstBrokerageRise) == '') {
              childWxStoreList[i].FirstBrokerageRiseName = ''
            }
            if (parseFloat(childWxStoreList[i].FirstBrokerageRise) == 40) {
              childWxStoreList[i].FirstBrokerageRiseName = '领跑官'
            }
            if (parseFloat(childWxStoreList[i].FirstBrokerageRise) == 60) {
              childWxStoreList[i].FirstBrokerageRiseName = '经销商'
            }
            if (parseFloat(childWxStoreList[i].FirstBrokerageRise) == 80 || parseFloat(childWxStoreList[i].FirstBrokerageRise) == 70 || parseFloat(childWxStoreList[i].FirstBrokerageRise) == 90 || parseFloat(childWxStoreList[i].FirstBrokerageRise) == 96) {
              childWxStoreList[i].FirstBrokerageRiseName = '代理商'
            }
          }
          that.setData({
            childWxStoreList: childWxStoreList,
            loadMoreHidden: res.data.Data.TotalPages
          })
        }
      }
    })
  },
  handleConfirm: function () {
    this.getChildWxStoreList();
  },
  handleInput: function (e) {
    this.setData({
      search: e.detail.value
    })
  },

  toReports: function (e) {
    let uid = e.currentTarget.dataset.uid;
    wx.navigateTo({
      url: '/merchant/merchants/businReports/index?childUid=' + uid + '&parentuid=' + app.globalData.userInfo.Uid + '&isAll=0'
    })
  },
  toAllReports: function () {
    wx.navigateTo({
      url: '/merchant/merchants/businReports/index?childUid=' + app.globalData.userInfo.Uid + '&parentuid=' + app.globalData.userInfo.Uid + '&isAll=1'
    })
  },
  loadMore: function () {
    let that = this;
    if (that.data.loadMoreHidden > 1 && that.data.currentPage < that.data.loadMoreHidden) {
      var currentPage = that.data.currentPage;
      that.setData({
        currentPage: currentPage + 1
      })
      that.getChildWxStoreList();
    } else {
      return
    }
  },

  onReachBottom: function(){
    this.loadMore();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }
})